package com.badguys.sum11proj;

import com.badguys.sum11proj.R;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


/**
 * @author Lane & Sam
 * Notes on Cursors
 * Cursors are database iterators. You must fetch rows from the database and 
 * then set the cursor toFirst by using Cursor.moveToFirst() before trying to 
 * use it. 
 * 
 * What the program does so far: Creates 3 SQL task queries
 * When the 'thanks' button is clicked, 1 of 3 tasks are displayed as TextViews
 * If 'no thanks' button is pressed, the program terminates.
 * This was our hack attempt at figuring out SQLite and Android SD and an
 * attempt to get the project rolling. Please feel free to remove any or all
 * code when working on this code we will not be offended.
 */


public class TaskMe extends Activity {
	private Button thanksButton;
	private Button noThanksButton;
	private TextView testView;
	private dbAdapter mDbHelper;
	private Cursor C;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
 
    	super.onCreate(savedInstanceState);  	
        this.setContentView(R.layout.main);  

        mDbHelper = new dbAdapter(this);
        mDbHelper.open();
	    
        mDbHelper.createTask("Don't forget to feed your cat.", "Every Day.");
        mDbHelper.createTask("Punch your fish.", "Every Day.");
        mDbHelper.createTask("Take a nap.", "Every Day.");
        C = mDbHelper.fetchAllTasks();
        C.moveToFirst();
        testView = (TextView)this.findViewById(R.id.testText);
        testView.setText("");
         
        /*
         * 'thanks button' at the moment cycles through tasks and displays them
         * as a text view when clicked.
         */
        thanksButton = (Button)this.findViewById(R.id.thanks);     
        thanksButton.setOnClickListener(new OnClickListener() {
	        public void onClick(View v) {
	        	
	        	 if(C.isAfterLast())
	        		 C.moveToFirst();
	        	
	        	 testView.setText(C.getString(1));
	        	 C.moveToNext();
	        		 
	    	}
        });
        
        /*
         * 'no thanks' buton.
         * closes application when it is clicked.
         */
        noThanksButton = (Button)this.findViewById(R.id.noThanks);
        noThanksButton.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		System.exit(0);
        	}
        });
        
	}
}